<template>
	<view class="page">
		<view class="main">
			<view class="item flex" style="padding: 20rpx 40rpx;">
				<view class="item-title">头像</view>
				<image src="@/static/img/avatar.png" v-if="!avatar" mode=""></image>
				<image :src="apifun.URLimg+avatar" v-if="avatar"  mode=""></image>
			</view>
			<view class="item flex">
				<view class="item-title">昵称</view>
				<view class="item-content" style="">
					<input type="text" disabled="" v-model="name" />
				</view>
			</view>
			<view class="item flex">
				<view class="item-title">年龄</view>
				<view class="item-content" style="">
					<input type="text" disabled="" v-model="age" />
				</view>
			</view>
			<view class="item flex">
				<view class="item-title">驾龄</view>
				<view class="item-content">
					<input type="text" disabled="" v-model="driveage" />
				</view>
			</view>
			<view class="item flex">
				<view class="item-title">所在城市</view>
				<view class="item-content">{{ city_name }}</view>
			</view>
			<view class="item flex">
				<view class="item-title">申请岗位</view>
				<view class="item-content" v-if="user_type == 0">陪驾教练</view>
				<view class="item-content" v-if="user_type == 1">验车教练</view>
				<view class="item-content" v-if="user_type == 2">陪驾教练+验车师</view>
			</view>
			<view class="item flex" @click="zxfun()">
				<view class="item-title">注销账号</view>
				<text class="tn-icon-right"></text>
			</view>
		</view>
		<view class="btn" @click="submit">保存</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				avatar: '',
				name:'',
				age:'',
				driveage:'',
				city:'',
				city_name:'',
				type:'',
				user_type:''
			};
		},
		onLoad() {
			this.usermsgfun()
		},
		methods: {
			submit(){
				let sendData = {
					avatar:this.avatar,
					username:this.name,
					age:this.age,
					drive_age:this.driveage,
					city:this.city,
					shape:this.shape
				};
				this.apifun.unirequest('/partner/user/setUserInfo','post',sendData,(res)=>{
					if(res.code === 200){
						let datas = res.data;
						this.apifun.toast('保存成功')
					}else{
						this.apifun.toast(res.msg)
					}
				})
			},
			zxfun(){
				let sendData = {
					mobile:uni.getStorageSync('usermsg').mobile,
					type:9,
				};
				this.apifun.unirequest('/partner/sms/sendSms','post',sendData,(res)=>{
					if(res.code === 200){
						let datas = res.data;
						this.apifun.navigate('/pages/my/logout')
					}else{
						this.apifun.toast('验证码'+res.msg)
					}
				})
			},
			upload(type) {
				this.apifun.uploadFileimg(res => {
					if(res.code == 200){
						this[type] = res.data.src
					}
				})
			},
			usermsgfun(){
				this.apifun.unirequest('/partner/user/getUserInfo','post',{},(res)=>{
					if(res.code === 200){
						let datas = res.data;
						uni.setStorageSync('usermsg', datas);
						this.avatar = datas.avatar,
						this.name = datas.username;
						this.age =datas.age;
						this.driveage = datas.drive_age;
						this.city = datas.city;
						this.city_name =  datas.city_name;
						this.type = datas.shap;
						this.user_type = datas.user_type;
					}else{
						this.apifun.toast(res.msg)
					}
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.page {
		padding: 20rpx 30rpx;
		box-sizing: border-box;
	}

	.main {
		border-radius: 20rpx;
		background: #FFFFFF;

		.item {
			justify-content: space-between;
			padding: 30rpx 40rpx;
			box-sizing: border-box;
			border-bottom: 2rpx solid #F6F6F6;

			.item-title {
				font-size: 30rpx;
				color: #333333;
			}
			.item-content{
				width: 50%;
				text-align: right;
				input{
					width: 100%;
					font-size: 26rpx;
					color: #333;
					text-align: right;
				}
			}
			image {
				width: 100rpx;
				height: 100rpx;
				border-radius: 50%;
			}
		}
	}
	.btn {
		margin-top: 110rpx;
		width: 550rpx;
	}
</style>